package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.DcFirst;
import com.ruoyi.service.fanruan.IDcFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地产集团Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/dc")
public class DcFirstController extends BaseController
{
    private String prefix = "fanruan/dc";

    @Autowired
    private IDcFirstService dcFirstService;

    @RequiresPermissions("fanruan:dc:view")
    @GetMapping()
    public String dc()
    {
        return "fanruan/dc/dc";
    }

    /**
     * 查询地产集团列表
     */
    @RequiresPermissions("fanruan:dc:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DcFirst dcFirst)
    {
        startPage();
        List<DcFirst> list = dcFirstService.selectDcFirstList(dcFirst);
        return getDataTable(list);
    }

    /**
     * 导出地产集团列表
     */
    @RequiresPermissions("fanruan:dc:export")
    @Log(title = "地产集团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DcFirst dcFirst)
    {
        List<DcFirst> list = dcFirstService.selectDcFirstList(dcFirst);
        ExcelUtil<DcFirst> util = new ExcelUtil<DcFirst>(DcFirst.class);
        return util.exportExcel(list, "dc");
    }

    /**
     * 新增地产集团
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/dc/add";
    }

    /**
     * 新增保存地产集团
     */
    @RequiresPermissions("fanruan:dc:add")
    @Log(title = "地产集团", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DcFirst dcFirst)
    {
        return toAjax(dcFirstService.insertDcFirst(dcFirst));
    }

    /**
     * 修改地产集团
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DcFirst dcFirst = dcFirstService.selectDcFirstById(id);
        mmap.put("dcFirst", dcFirst);
        return "fanruan/dc/edit";
    }

    /**
     * 修改保存地产集团
     */
    @RequiresPermissions("fanruan:dc:edit")
    @Log(title = "地产集团", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DcFirst dcFirst)
    {
        return toAjax(dcFirstService.updateDcFirst(dcFirst));
    }

    /**
     * 删除地产集团
     */
    @RequiresPermissions("fanruan:dc:remove")
    @Log(title = "地产集团", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dcFirstService.deleteDcFirstByIds(ids));
    }
}
